﻿Imports CalificadorPremiosOscarBLL.pcs.Login

Public Class LoginForm
    Inherits UIBase

    ' TODO: Insert code to perform custom authentication using the provided username and password 
    ' (See http://go.microsoft.com/fwlink/?LinkId=35339).  
    ' The custom principal can then be attached to the current thread's principal as follows: 
    '     My.User.CurrentPrincipal = CustomPrincipal
    ' where CustomPrincipal is the IPrincipal implementation used to perform authentication. 
    ' Subsequently, My.User will return identity information encapsulated in the CustomPrincipal object
    ' such as the username, display name, etc.

    Private _admonMode As Boolean = False

    Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        Me.EventoActual = Eventos.BUSQUEDA
        Me.Height = 221
        Try
            If validarInput() Then
                If LoginFasade.login(Me.UsernameTextBox.Text, Me.PasswordTextBox.Text, _admonMode) Then
                    If _admonMode Then
                        CargarPantallaAdministrador()
                    Else

                    End If
                    Me.Dispose()
                    Me.Close()
                Else
                    MostrarMensajeDeError()
                End If
                Else
                    MostrarMensajeDeError()
                End If
        Catch ex As Exception
            MessageBoxFactory.exceptionGeneral(ex)
        End Try
    End Sub

    Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
        Me.Close()
    End Sub

    Property AdmonMode() As Boolean
        Get
            Return Me._admonMode
        End Get
        Set(value As Boolean)
            Me._admonMode = value
        End Set
    End Property

    Private Sub retornarTipoInicioSesion()
        FormulariosFactory.crearTipoInicioSesion(Me.MdiParent).Show()
    End Sub

    Private Sub LoginForm_FormClosing(sender As System.Object, e As System.EventArgs) Handles MyBase.FormClosing
        retornarTipoInicioSesion()
    End Sub

    Private Sub LoginForm_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        Me.Height = 221
        If Me.AdmonMode Then
            Me.LinkLabelCrearCuenta.Hide()
        End If
    End Sub

    Private Sub MostrarMensajeDeError()
        Me.Height = 250
        Me.UsernameTextBox.Focus()
        Me.PasswordTextBox.Clear()
    End Sub

    Private Sub CargarPantallaAdministrador()
        Dim temp As Form = Me.MdiParent
        temp.MainMenuStrip.Hide()
        temp.MainMenuStrip = temp.Controls("MenuStripAdministrador")
        temp.MainMenuStrip.Show()
        temp.Text = FormulariosFactory.obtenerNombreApp & " - Vista de Administrador - " & Me.UsernameTextBox.Text
        CalificadorPremiosOscarUI.FormulariosFactory.crearAdministracionCeremonia(Me.MdiParent).Show()
        'Me.MdiParent.LayoutMdi(MdiLayout.Cascade)
    End Sub

    Private Sub CargarPantallaVotante()
        Dim temp As Form = Me.MdiParent
        temp.MainMenuStrip.Hide()
        temp.MainMenuStrip = temp.Controls("MenuStripVotante")
        temp.MainMenuStrip.Show()
    End Sub

#Region "Validaciones Formulario"
    'region para las validaciones de entrada de usuarios

    Public Overloads Function validarInput() As Boolean
        If Me.UsernameTextBox.Text = vbNullString Or _
            Me.PasswordTextBox.Text = vbNullString Then
            Return False
        Else
            Return True
        End If
    End Function

#End Region

End Class
